package com.aorise.controller.map;

import com.aorise.exception.DataValidationException;
import com.aorise.service.order.RepairCameraService;
import com.aorise.utils.StatusDefine;
import com.aorise.utils.StatusDefineMessage;
import com.aorise.utils.json.JsonResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: zhouhao
 * @Date: 2019/6/18
 * @Description:    电子地图控制器
 */
@Slf4j
@RestController
@RequestMapping("api/map")
@RequiresPermissions("DZDTFW")
@Api(description ="电子地图控制器")
public class ElectronicMapController {

    @Autowired
    private RepairCameraService repairCameraService;

    @ApiOperation(value = "电子地图设备总数", httpMethod = "GET", response = String.class, notes = "电子地图设备总数，提供电子地图使用")
    @RequestMapping(value = "/getMapInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getMapInfo() {

        try{
            return JsonResponseData.ofSuccess(repairCameraService.getMapInfo());
        }catch (DataValidationException e) {
            log.error(
                    "controller:ElectronicMapController. function:getMapInfo...msg: getMapInfo DataValidationException");
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.DATA_FORMAT_ERROR,
                    e.getMessage(), null).toString();
        }catch (DataAccessException e) {
            e.printStackTrace();
            log.error(
                    "controller:ElectronicMapController. function:getMapInfo...msg:getMapInfo DataAccessException. error:"
                            + e.getMessage());
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.DB_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.DB_ERROR), null).toString();
        } catch (Exception e) {
            log.error(
                    "controller:ElectronicMapController. function:getMapInfo...msg:getMapInfo Exception. error:"
                            + e.getMessage());
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.SYS_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.SYS_ERROR), null).toString();
        }
    }

    @ApiOperation(value = "电子地图设备信息", httpMethod = "GET", response = String.class, notes = "电子地图设备信息，提供电子地图使用")
    @RequestMapping(value = "/getMapCameraInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getMapCameraInfo() {

        try{
            return JsonResponseData.ofSuccess(repairCameraService.getMapCameraInfo());
        }catch (DataValidationException e) {
            log.error(
                    "controller:ElectronicMapController. function:getMapCameraInfo...msg: getMapCameraInfo DataValidationException");
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.DATA_FORMAT_ERROR,
                    e.getMessage(), null).toString();
        }catch (DataAccessException e) {
            e.printStackTrace();
            log.error(
                    "controller:ElectronicMapController. function:getMapCameraInfo...msg:getMapCameraInfo DataAccessException. error:"
                            + e.getMessage());
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.DB_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.DB_ERROR), null).toString();
        } catch (Exception e) {
            log.error(
                    "controller:ElectronicMapController. function:getMapCameraInfo...msg:getMapCameraInfo Exception. error:"
                            + e.getMessage());
            log.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.SYS_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.SYS_ERROR), null).toString();
        }
    }
}
